<?php

namespace app\api\model\ad;
use app\common\model\ad\Ad as AdModel;
/**
 * 广告模型
 */
class Ad extends AdModel
{

    public function getLists($params, $Limit=10, $SupplierId=0, $type=0){
        $model = $this;
        $model = $model->where($params);
        if($type==1){
            $model = $model->where('shop_supplier_id','=',0);
            $model = $model->where('audit_status','=',1)->where('status','=',1);
        }elseif($type==2){

        }else{
            $model = $model->where('audit_status','=',1)->where('status','=',1);
            //权重： 商户->代理->平台
            $model = $model->where(function ($query) use ($SupplierId) {
                $query->when($SupplierId>0,function ($query) use ($SupplierId) {
                    $query->where('shop_supplier_id','=',0)  ->whereOr('shop_supplier_id','=',$SupplierId);
                },function ($query) {
                    $query->where('shop_supplier_id','=',0);
                });
            });
        }
        if($Limit<=0)$Limit=10;
        $list = $model->with(['image','category'])
            ->order(['market' => 'desc', 'shop_supplier_id' => 'desc', 'sort' => 'asc'])
            ->limit($Limit)
            ->select();
            // dump($list);exit;
        return $list;
    }
}